using AForge.Video;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
namespace SilverSea.Video.Tools
{
	public class CameraSettingPage : UserControl, IWizardPage
	{
		private IContainer icontainer_0;
		private IVideoSourcePage ivideoSourcePage_0;
		private EventHandler eventHandler_0;
		private EventHandler eventHandler_1;
		private Camera camera_0;
		private int int_0 = -1;
		private bool bool_0;
		public event EventHandler StateChanged
		{
			add
			{
				EventHandler eventHandler = this.eventHandler_0;
				EventHandler eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler value2 = (EventHandler)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler>(ref this.eventHandler_0, value2, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
			remove
			{
				EventHandler eventHandler = this.eventHandler_0;
				EventHandler eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler value2 = (EventHandler)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler>(ref this.eventHandler_0, value2, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
		}
		public event EventHandler Reset
		{
			add
			{
				EventHandler eventHandler = this.eventHandler_1;
				EventHandler eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler value2 = (EventHandler)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler>(ref this.eventHandler_1, value2, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
			remove
			{
				EventHandler eventHandler = this.eventHandler_1;
				EventHandler eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler value2 = (EventHandler)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler>(ref this.eventHandler_1, value2, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
		}
		public Camera Camera
		{
			get
			{
				return this.camera_0;
			}
			set
			{
				if (value != null)
				{
					this.camera_0 = value;
					if (this.ivideoSourcePage_0 != null)
					{
						this.ivideoSourcePage_0.VideoSource = this.camera_0.VideoSource;
						this.ivideoSourcePage_0.Login = this.camera_0.Login;
						this.ivideoSourcePage_0.Password = this.camera_0.Password;
						this.ivideoSourcePage_0.StreamType = (int)this.camera_0.StreamType;
						this.ivideoSourcePage_0.ProtocolType = (int)this.camera_0.ProtocolType;
						this.ivideoSourcePage_0.Chanel = this.camera_0.Chanel;
						this.ivideoSourcePage_0.Resolution = this.camera_0.Resolution;
						this.ivideoSourcePage_0.Quality = this.camera_0.Quality;
						this.ivideoSourcePage_0.FrameRate = this.camera_0.FrameRate;
						this.ivideoSourcePage_0.UsingPlugins = this.camera_0.UsingPlugins;
                        this.bool_0 = this.ivideoSourcePage_0.Completed;
					}
				}
			}
		}
		public int CameraType
		{
			get
			{
				return this.int_0;
			}
			set
			{
				if (this.int_0 == -1 || this.int_0 != value)
				{
					if (this.ivideoSourcePage_0 != null)
					{
						base.Controls.Remove((Control)this.ivideoSourcePage_0);
					}
					this.bool_0 = false;
					this.int_0 = value;
					if (this.int_0 > -1)
					{
						if (CameraTypes.GetType(this.int_0) == SilverSea.Video.Tools.CameraType.VideoCaptureDevice)
						{
							this.ivideoSourcePage_0 = new VideoCaptureDeviceSettingPage();
						}
						else
						{
							if (CameraTypes.GetType(this.int_0) == SilverSea.Video.Tools.CameraType.VideoFile)
							{
								this.ivideoSourcePage_0 = new VideoFileSettingPage();
							}
							else
							{
								this.ivideoSourcePage_0 = new IPCameraSettingPage();
							}
						}
						if (this.ivideoSourcePage_0 != null)
						{
							Control control = (Control)this.ivideoSourcePage_0;
							control.Dock = DockStyle.Fill;
							base.Controls.Add(control);
							this.ivideoSourcePage_0.StateChanged += new EventHandler(this.ivideoSourcePage_0_StateChanged);
							this.ivideoSourcePage_0.VideoSource = this.camera_0.VideoSource;
							this.ivideoSourcePage_0.Login = this.camera_0.Login;
							this.ivideoSourcePage_0.Password = this.camera_0.Password;
							this.ivideoSourcePage_0.StreamType = (int)this.camera_0.StreamType;
							this.ivideoSourcePage_0.ProtocolType = (int)this.camera_0.ProtocolType;
							this.ivideoSourcePage_0.Chanel = this.camera_0.Chanel;
							this.ivideoSourcePage_0.Resolution = this.camera_0.Resolution;
							this.ivideoSourcePage_0.Quality = this.camera_0.Quality;
							this.ivideoSourcePage_0.FrameRate = this.camera_0.FrameRate;
							this.ivideoSourcePage_0.UsingDeinterlaceFilter = this.camera_0.UsingDeinterlaceFilter;
							this.ivideoSourcePage_0.DeinterlaceFilterName = this.camera_0.DeinterlaceFilterName;
							this.ivideoSourcePage_0.UsingPlugins = this.camera_0.UsingPlugins;
                            this.bool_0 = this.ivideoSourcePage_0.Completed;
						}
					}
				}
			}
		}
		public string PageName
		{
			get
			{
				return "Thông số Camera";
			}
		}
		public string PageDescription
		{
			get
			{
				string text = "Bước 2: Thiết lập thông số Camera\n";
				if (this.int_0 > -1)
				{
					text = text + "             " + CameraTypes.GetType(this.int_0).ToString();
				}
				return text;
			}
		}
		public bool Completed
		{
			get
			{
				return this.bool_0;
			}
		}
		public CameraSettingPage()
		{
			this.InitializeComponent();
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.icontainer_0 != null)
			{
				this.icontainer_0.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
            this.SuspendLayout();
            // 
            // CameraSettingPage
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Name = "CameraSettingPage";
            this.Size = new System.Drawing.Size(414, 255);
            this.ResumeLayout(false);

		}
		public void Display()
		{
			if (this.ivideoSourcePage_0 != null)
			{
				((Control)this.ivideoSourcePage_0).Show();
				this.ivideoSourcePage_0.Display();
			}
		}
		public bool Apply()
		{
			bool result = false;
			if (this.ivideoSourcePage_0 != null && (result = this.ivideoSourcePage_0.Apply()))
			{
                this.camera_0.VideoSource = this.ivideoSourcePage_0.VideoSource;
                this.camera_0.Login = this.ivideoSourcePage_0.Login;
                this.camera_0.Password = this.ivideoSourcePage_0.Password;
                this.camera_0.StreamType = (StreamType)this.ivideoSourcePage_0.StreamType;
                this.camera_0.ProtocolType = (ProtocolType)this.ivideoSourcePage_0.ProtocolType;
                this.camera_0.Chanel = this.ivideoSourcePage_0.Chanel;
                this.camera_0.Resolution = this.ivideoSourcePage_0.Resolution;
                this.camera_0.Quality = this.ivideoSourcePage_0.Quality;
                this.camera_0.FrameRate = this.ivideoSourcePage_0.FrameRate;
                this.camera_0.UsingDeinterlaceFilter = this.ivideoSourcePage_0.UsingDeinterlaceFilter;
                this.camera_0.DeinterlaceFilterName = this.ivideoSourcePage_0.DeinterlaceFilterName;
                this.camera_0.UsingPlugins = this.ivideoSourcePage_0.UsingPlugins;
			}
			return result;
		}
		private void ivideoSourcePage_0_StateChanged(object sender, EventArgs e)
		{
            this.bool_0 = this.ivideoSourcePage_0.Completed;
			if (this.eventHandler_0 != null)
			{
				this.eventHandler_0(this, new EventArgs());
			}
		}
	}
}
